//
// Created by dxyinme on 2021/11/14.
//

#include "test_comm.h"

class ConditionIfTest : public TestComm {
  void SetUp() override {
    TestComm::SetUp();
  }

  void TearDown() override {
    TestComm::TearDown();
  }
};

using namespace FPStyle;

TEST_F(ConditionIfTest, TestIfAndElse) {
  auto Task = [] (int o) -> int {
    int res = 0;
    if (0 <= o && o <= 10) {
      res = 1;
    } else if (12 <= o && o <= 17) {
      res = 2;
    } else if (23 <= o) {
      res = 3;
    }
    return res;
  };

  auto FpTask = [] (int o) {
    int res = 0;
    IfElse(And(0 <= o, o <= 10), [&] {
      res = 1;
    }, [&] {
      IfElse(And(12 <= o, o <= 17), [&] {
        res = 2;
      }, [&] {
        If(23 <= o, [&] {
          res = 3;
        });
      });
    });
    return res;
  };

  for (int i = -1000; i <= 1000; i++) {
    EXPECT_EQ(Task(i), FpTask(i));
  }
}